package com.fz.service.merchant.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.common.ResponseEntity;
import com.fz.dto.merchant.merDept.MerDeptAdd;
import com.fz.dto.merchant.merDept.MerDeptQuery;
import com.fz.dto.merchant.merDept.MerDeptUpd;
import com.fz.entity.merchant.MerDept;
import com.fz.mapper.merchant.MerDeptMapper;
import com.fz.service.merchant.MerDeptService;
import com.fz.vo.merchant.merDept.MerDeptVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@SuppressWarnings("unchecked")
public class MerDeptServiceImpl implements MerDeptService {

    @Resource
    private MerDeptMapper merDeptMapper;

    /**
     * @方法描述:  分页查找部门
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/17
     */
    @Override
    public ResponseEntity<IPage<MerDeptVo>> findMerDeptList(MerDeptQuery merDeptQuery, int pageNum, int pageSize) throws Exception {
        Page<MerDept> page = new Page<>(pageNum,pageSize);
        IPage<MerDeptVo> DeptQueryDataList = merDeptMapper.findMerDeptList(page,merDeptQuery);
        return ResponseEntity.buildSuccess(DeptQueryDataList);
    }

    /**
     * @方法描述:  新增部门
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/17
     */
    @Override
    public ResponseEntity addMerDept(MerDeptAdd merDeptAdd) {
        MerDept dept = new MerDept();
        dept.setName(merDeptAdd.getName());
        dept.setPid(merDeptAdd.getPid());
        dept.setStatus(merDeptAdd.getStatus());
        merDeptMapper.insert(dept);
        return ResponseEntity.buildSuccess();
    }

    /**
     * @方法描述:  更改部门
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/17
     */
    @Override
    public ResponseEntity updateMerDept(MerDeptUpd merDeptUpd) {
        MerDept dept = new MerDept();
        dept.setId(merDeptUpd.getId());
        dept.setStatus(merDeptUpd.getStatus());
        dept.setName(merDeptUpd.getName());
        dept.setPid(merDeptUpd.getPid());
        merDeptMapper.updateById(dept);
        return ResponseEntity.buildSuccess();
    }

    /**
     * @方法描述:  查询下拉框内部门的信息
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/19
     */
    @Override
    public ResponseEntity<List<MerDept>> findMerDeptInSelect() {
        LambdaQueryWrapper<MerDept> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //  1    是禁用的状态标识符，查询被禁用的公司
        lambdaQueryWrapper.eq(MerDept::getStatus, 1);
        List<MerDept> deptVos = merDeptMapper.selectList(lambdaQueryWrapper);
        return ResponseEntity.buildSuccess(deptVos);
    }
}
